package com.xjzd.std.concurrency;

import java.util.concurrent.CountDownLatch;

public class CountDownLatchDemo1 {
    public static void main(String[] args) throws InterruptedException {
        final CountDownLatch wg = new CountDownLatch(1000);
        for (int i = 0; i < 1000; i++) {
            final int temp = i;
            new Thread(() -> {
                long sum = 0;
                for (int j = 0; j < 100000000; j++) {
                    sum += j;
                }
                System.out.printf("%d sum = %d\n", temp, sum);
                wg.countDown();
            }).start();
        }
        wg.await();
    }
}
